package com.gwq.computed;

import lombok.Data;

import java.util.Random;

@Data
public class BinaryOperation {

    static final int UPPER = 100;
    static final int LOWER = 0;

    private int left_operand = 0,right_operand=0;
    private char operator = '+';
    private int value = 0;

    private void construct(int left,int  right,char op){
        left_operand = left;
        right_operand = right;
        operator = op;
        if(op=='+'){
            value = left+right;
        }else{
            value = left-right;
        }
    }

    public BinaryOperation generateAdditionOperation(){
        Random random = new Random();
        int left,right,result;
        left = random.nextInt(UPPER+1);
        do{
            right = random.nextInt(UPPER+1);
            result = left+right;
        }while (result>UPPER);
        BinaryOperation binaryOperation = new BinaryOperation();
        binaryOperation.construct(left,right,'+');
        return binaryOperation;
    }

    public boolean equals(BinaryOperation binaryOperation){
        return left_operand == binaryOperation.getLeft_operand()&
                right_operand == binaryOperation.getRight_operand()&
                operator == binaryOperation.getOperator();
    }


    public String toString(){
        return left_operand+""+operator+""+right_operand;
    }

    public String asString(){
        return left_operand+""+operator+""+right_operand+"=";
    }

    public String fullString(){
        return left_operand+""+operator+""+right_operand+"="+value;
    }


}
